# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=usrsctp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.3.0
pkgrel=1
pkgdesc="A portable SCTP userland stack (mingw-w64)"
arch=('any')
url='https://github.com/sctplab/usrsctp'
license=('Custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=()
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/sctplab/${_realname}/archive/${pkgver}.tar.gz"
        "0001-add-mingw-support.patch")
sha256sums=('a4573b1cd7b8fc2fce476df61093736d3fea9eef5c87d72e66768c0a6b1f9e39'
            '398ed22c694e3bbcb6ce30ccc51ac6600e3732b61e084962bc6866a2d319e615')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p2 -i ${srcdir}/0001-add-mingw-support.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  ./bootstrap
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    CFLAGS="-DSCTP_DEBUG -DSCTP_SIMPLE_ALLOCATOR -DSCTP_PROCESS_LEVEL_LOCKS -D__Userspace__ -D__Userspace_os_Windows -DINET -DINET6 -D_LIB -DWINVER=0x0A00 -D_WIN32_WINNT=0x0A00 -Usocklen_t" \
    --disable-warnings-as-errors LIBS="-lws2_32 -liphlpapi"

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install-strip DESTDIR="${pkgdir}"
}
